package com.slfx.schedule;

import java.time.LocalDateTime;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zengqingfa
 * @className ScheduleAtFixedRateMethodTest
 * @description
 * @create 2022/8/20 15:38
 */
public class ScheduleAtFixedRateMethodTest {
    public static void main(String[] args) {
        ScheduledExecutorService respScheduler = new ScheduledThreadPoolExecutor(2);
        System.out.println("task begin:" + LocalDateTime.now());
        respScheduler.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);//2000
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "--task run:" +LocalDateTime.now());
            }
        }, 2, 3, TimeUnit.SECONDS);
    }

}